<?php

namespace app\api\controller\fp;

use app\common\model\User;
use Throwable;
use think\Response;
use app\common\library\Upload;
use app\common\controller\Frontend;

class Repost extends Frontend
{
    protected array $noNeedLogin = [];

    protected array $noNeedPermission = ['upload'];

    public function initialize(): void
    {
        parent::initialize();

    }

    /**
     * 转发动态
     */
    public function repost()
    {
        $data = $this->request->post();
        $originalPost = \app\common\model\fp\Post::find($data['original_post_id']);

        if (!$originalPost) {
            $this->error(__('original post not found'), null, 0, null, ['statusCode' => 404]);
        }

        $repost = new \app\common\model\fp\Repost();
        $repost->user_id = $this->auth->id;
        $repost->original_post_id = $data['original_post_id'];
        $repost->comment = $data['comment'] ?? null;
        $repost->save();

        $this->success(__('repost success'));
    }
}